using UnityEngine;

public class EnemyState_LangGongShou_追击 : EnemyStateBase_LangGongShou
{
	private Vector2 _targetPos;

	private Vector2 _StartPos;

	private float _Speed = 2f;

	private Vector2 _DirSpeed;

	private bool _靠近玩家;

	private float _离开视野时间;

	public override void OnEnter()
	{
		_离开视野时间 = 0f;
		_StartPos = _Mono.transform.position;
		Vector2 vector = _Mono._Tsf_玩家.position;
		if (Vector2.Distance(_StartPos, vector) > 35f)
		{
			_靠近玩家 = false;
			_Mono._Ani.Play("移动");
			_targetPos = vector + new Vector2((float)((vector.x < _StartPos.x) ? 1 : (-1)) * Random.Range(1.5f, 25f), Random.Range(-0.5f, 0.5f));
			_Mono.transform.localScale = new Vector3((vector.x > _StartPos.x) ? 1 : (-1), 1f, 1f);
			_DirSpeed = (_targetPos - _StartPos).normalized * _Speed;
			_Mono._Tsf_移动目标.transform.position = _targetPos;
			if (_Mono._Is视野范围内)
			{
				_Timer = Random.Range(1.5f, 2.25f);
			}
			else
			{
				_Timer = Random.Range(1f, 2f);
			}
		}
		else
		{
			_靠近玩家 = false;
			_Mono._Ani.Play("站立");
			_Timer = Random.Range(1.5f, 2.5f);
		}
	}

	public override void OnExit()
	{
	}

	public override void OnUpdate()
	{
		_Timer -= Time.deltaTime * _Speed;
		if (_靠近玩家)
		{
			_Mono._Rb2D.velocity = _DirSpeed;
			if (!_Mono._Is视野范围内)
			{
				_离开视野时间 += Time.deltaTime;
				if (_离开视野时间 >= 3f)
				{
					_Mono._Is追击中 = false;
					_Mono._Rb2D.velocity = Vector2.zero;
					_Mono.ChangeState(StateType_Enemy_LangGongShou.站立);
				}
			}
			else
			{
				_离开视野时间 = 0f;
			}
		}
		else if (_Timer < 0f)
		{
			if (_Mono._Is视野范围内 && Random.value < 0.7f)
			{
				_Mono.ChangeState(StateType_Enemy_LangGongShou.攻击);
			}
			else
			{
				_Mono.ChangeState(StateType_Enemy_LangGongShou.追击);
			}
		}
	}
}
